import 'package:finder/finder.dart';
import 'package:finder_example/image_page.dart';
import 'package:finder_example/res.dart';
import 'package:flutter/material.dart';

import 'download_page.dart';

const weChat =
    'https://plugins.jetbrains.com/plugin/download?rel=true&updateId=575323';
// const weChat = 'https://services.gradle.org/distributions/gradle-8.14.3-bin.zip';
// const image = 'https://pic4.zhimg.com/v2-43f8f1ab2ad7ae1848c4ae21ef0cadc4_r.jpg?source=1940ef5c';
const image =
    'https://img-blog.csdnimg.cn/20190821180949916.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1VlbWluZw==,size_16,color_FFFFFF,t_70';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('download demo'),
        ),
        body: HomePage(),
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  void _jumpTo(BuildContext context, Widget page) {
    Navigator.push(context, MaterialPageRoute(builder: (_) => page));
    print('finder---jump');
  }

  Widget _buildButton(BuildContext context, String text, Widget nextPage) {
    return MaterialButton(
      onPressed: () => {
        _jumpTo(context, nextPage),
        print('finder---click'),
      },
      child: Text(text, style: TextStyle(fontSize: 20)),
      color: Theme.of(context).primaryColor,
      minWidth: double.infinity,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          _buildButton(
            context,
            '本地图片案例',
            ImagePage(
              withAsset(assetName: Res.ic_avatar),
              title: '本地图片案例',
            ),
          ),
          _buildButton(
            context,
            '网络图片案例',
            ImagePage(
              Uri.parse(image),
              title: '网络图片案例',
            ),
          ),
          _buildButton(
            context,
            '文件下载案例',
            DownloadPage(
              Uri.parse(weChat),
              title: '文件下载案例',
            ),
          ),
        ],
      ),
    );
  }
}
